<template>
  <div class="login">
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
      <h3 class="title">{{ title }}</h3>
      <!-- 改造登录方式选择区域 -->
      <div v-if="listMenu.length > 0" class="role-selection">
        <div class="role-title">选择登录方式</div>
        <div class="role-container">
          <div v-for="item in listMenu" :key="item.roleId" class="role-card"
            :class="{ active: selectedRole === item.roleId }" @click="selectRole(item)">
            <div class="role-icon">
              <i class="el-icon-user-solid"></i>
            </div>
            <div class="role-label">{{ item.roleName }}</div>
            <div class="check-mark" v-if="selectedRole === item.roleId">
              <i class="el-icon-check"></i>
            </div>
          </div>
        </div>
      </div>
      <div class="form-content">
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
            <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码"
            @keyup.enter.native="handleLogin">
            <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
          </el-input>
        </el-form-item>
        <!-- <el-form-item prop="code" v-if="captchaEnabled">
          <el-input
            v-model="loginForm.code"
            auto-complete="off"
            placeholder="验证码"
            style="width: 63%"
            @keyup.enter.native="handleLogin"
          >
            <svg-icon
              slot="prefix"
              icon-class="validCode"
              class="el-input__icon input-icon"
            />
          </el-input>
          <div class="login-code">
            <img :src="codeUrl" @click="getCode" class="login-code-img" />
          </div>
        </el-form-item> -->
        <el-checkbox v-model="loginForm.rememberMe" style="margin: 0px 0px 25px 0px">记住密码</el-checkbox>
        <el-form-item style="width: 100%">
          <el-button :loading="loading" size="medium" type="primary" style="width: 100%"
            @click.native.prevent="handleLogin">
            <span v-if="!loading">登 录</span>
            <span v-else>登 录 中...</span>
          </el-button>
          <div style="float: right" v-if="register">
            <router-link class="link-type" :to="getRegisterLink()">忘记密码</router-link>
          </div>
        </el-form-item>
      </div>
    </el-form>
    <!--  底部  -->
    <div class="el-login-footer">
      <span>Copyright © 2018-2025 心语云学生心理智慧服务平台 All Rights Reserved.</span>
    </div>
  </div>
</template>

<script>
import { getCodeImg, getOptionselect } from "@/api/login";
import Cookies from "js-cookie";
import { encrypt, decrypt } from "@/utils/jsencrypt";

export default {
  name: "Login",
  data() {
    return {
      listMenu: [],
      title: process.env.VUE_APP_TITLE,
      codeUrl: "",
      loginForm: {
        username: "",
        password: "",
        rememberMe: false,
        code: "",
        uuid: "",
        roleId: null,
      },
      loginRules: {
        username: [{ required: true, trigger: "blur", message: "请输入您的账号" }],
        password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
        code: [{ required: true, trigger: "change", message: "请输入验证码" }],
      },
      loading: false,
      // 验证码开关
      captchaEnabled: true,
      // 注册开关
      register: true,
      redirect: undefined,
      selectedRole: null,
    };
  },
  watch: {
    $route: {
      handler: function (route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true,
    },
  },
  created() {
    console.log(this.$route.query.isAdmin);
    this.getCode();
    this.getCookie();
    // this.loadRoles();
  },
  mounted() {
    this.loadRoles();
  },
  methods: {
    loadRoles() {
      this.$nextTick(() => {
        var _this = this
        var is = this.$route.query.isAdmin;
        getOptionselect({ isAdmin: is })
          .then((res) => {
            console.log('获取角色列表响应:', res);
            if (res && res.data) {
              this.listMenu = res.data;
              if (_this.$route.query.isAdmin && _this.$route.query.isAdmin !== "false") {
                this.listMenu = this.listMenu.filter((item) => item.roleId === 1);
                if (this.listMenu.length > 0) {
                  this.selectRole(this.listMenu[0]);
                }
              } else {
                if (this.listMenu.length > 0) {
                  this.selectRole(this.listMenu[0]);
                }
              }
              // 验证 DOM 元素
              this.$nextTick(() => {
                const roleSelection = document.querySelector('.role-selection');
              });
            } else {
            }
          })
          .catch((err) => {
            this.$message.error("获取角色列表失败，请刷新页面重试");
          });
      });
    },
    getCode() {
      getCodeImg().then((res) => {
        this.captchaEnabled =
          res.captchaEnabled === undefined ? true : res.captchaEnabled;
        if (this.captchaEnabled) {
          this.codeUrl = "data:image/gif;base64," + res.img;
          this.loginForm.uuid = res.uuid;
        }
      });
    },
    getCookie() {
      const username = Cookies.get("username");
      const password = Cookies.get("password");
      const rememberMe = Cookies.get("rememberMe");
      this.loginForm = {
        username: username === undefined ? this.loginForm.username : username,
        password: password === undefined ? this.loginForm.password : decrypt(password),
        rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
      };
    },
    handleLogin() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          // 如果有可选角色但未选择，提示用户
          if (this.listMenu.length > 0 && !this.selectedRole) {
            this.$message({
              message: "请选择登录方式",
              type: "warning",
            });
            return;
          }

          this.loading = true;
          if (this.loginForm.rememberMe) {
            Cookies.set("username", this.loginForm.username, { expires: 30 });
            Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
            Cookies.set("rememberMe", this.loginForm.rememberMe, { expires: 30 });
          } else {
            Cookies.remove("username");
            Cookies.remove("password");
            Cookies.remove("rememberMe");
          }
          this.$store
            .dispatch("Login", this.loginForm)
            .then(() => {
              this.$router.push({ path: this.redirect || "/" }).catch(() => { });
            })
            .catch(() => {
              this.loading = false;
              if (this.captchaEnabled) {
                this.getCode();
              }
            });
        }
      });
    },
    selectRole(item) {
      this.selectedRole = item.roleId;
      this.loginForm.roleId = item.roleId;
    },

    // 获取忘记密码链接，保持isAdmin参数
    getRegisterLink() {
      const isAdmin = this.$route.query.isAdmin;
      if (isAdmin !== undefined) {
        return `/register?isAdmin=${isAdmin}`;
      }
      return '/register';
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss">
// 全局主体样式
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(-45deg, #667eea 0%, #764ba2 50%, #8b5cf6 100%);
  background-size: 400% 400%;
  animation: gradientShift 12s ease infinite;
  position: relative;
  overflow: hidden;
  font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

  // 动态粒子背景
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 20% 50%, rgba(102, 126, 234, 0.3) 0%, transparent 50%),
      radial-gradient(circle at 80% 20%, rgba(139, 92, 246, 0.3) 0%, transparent 50%),
      radial-gradient(circle at 40% 80%, rgba(120, 119, 198, 0.2) 0%, transparent 50%);
    animation: particleFloat 20s ease-in-out infinite alternate;
    z-index: 1;
  }

  // 几何装饰元素
  &::after {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    background: linear-gradient(45deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
    border-radius: 50%;
    top: -300px;
    right: -300px;
    animation: geometryRotate 30s linear infinite;
    z-index: 1;
  }
}

// 动画定义
@keyframes gradientShift {

  0%,
  100% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }
}

@keyframes particleFloat {

  0%,
  100% {
    transform: translateY(0px) rotate(0deg);
    opacity: 1;
  }

  50% {
    transform: translateY(-20px) rotate(180deg);
    opacity: 0.8;
  }
}

@keyframes geometryRotate {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

// 标题样式 - 发光效果
.title {
  margin: 0 auto 30px auto;
  text-align: center;
  color: #fff;
  font-size: 28px;
  font-weight: 800;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.5),
    0 0 40px rgba(120, 119, 198, 0.4),
    0 0 60px rgba(120, 119, 198, 0.3);
  letter-spacing: 2px;
  position: relative;
  animation: titleGlow 3s ease-in-out infinite alternate;
  background: linear-gradient(45deg, #fff, #e0e7ff, #c7d2fe);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.3));

  &::after {
    content: '';
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 3px;
    background: linear-gradient(90deg, #667eea, #764ba2, #8b5cf6);
    border-radius: 3px;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
    animation: lineGlow 2s ease-in-out infinite alternate;
  }
}

@keyframes titleGlow {
  0% {
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5),
      0 0 40px rgba(120, 119, 198, 0.4),
      0 0 60px rgba(120, 119, 198, 0.3);
  }

  100% {
    text-shadow: 0 0 30px rgba(255, 255, 255, 0.8),
      0 0 60px rgba(120, 119, 198, 0.6),
      0 0 90px rgba(120, 119, 198, 0.5);
  }
}

@keyframes lineGlow {
  0% {
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
    transform: translateX(-50%) scaleX(1);
  }

  100% {
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.8);
    transform: translateX(-50%) scaleX(1.1);
  }
}

// 主表单样式 - 磨砂玻璃效果
.login-form {
  position: relative;
  z-index: 10;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  width: 540px;
  padding: 40px 20px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset,
    0 8px 32px rgba(120, 119, 198, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transform: translateY(0);
  transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
  animation: formSlideIn 0.8s ease-out forwards;

  // 新增的内发光效果
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 24px;
    padding: 1px;
    background: linear-gradient(45deg,
        rgba(255, 255, 255, 0.1),
        rgba(102, 126, 234, 0.1),
        rgba(139, 92, 246, 0.1),
        rgba(255, 255, 255, 0.1));
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask-composite: exclude;
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    animation: borderRotate 6s linear infinite;
    z-index: -1;
  }

  &:hover {
    transform: translateY(-8px);
    box-shadow: 0 35px 70px rgba(0, 0, 0, 0.2),
      0 0 0 1px rgba(255, 255, 255, 0.15) inset,
      0 12px 48px rgba(120, 119, 198, 0.3);
  }

  .form-content {
    margin-top: 20px;
  }

  .el-input {
    height: 52px;
    margin-bottom: 16px;

    input {
      height: 52px;
      padding-left: 50px;
      background: rgba(255, 255, 255, 0.05);
      border-radius: 16px;
      border: 1px solid rgba(255, 255, 255, 0.1);
      color: #fff;
      font-size: 15px;
      font-weight: 400;
      transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
      backdrop-filter: blur(10px);
      -webkit-backdrop-filter: blur(10px);

      &::placeholder {
        color: rgba(255, 255, 255, 0.5);
        font-weight: 400;
      }

      &:focus {
        background: rgba(255, 255, 255, 0.1);
        border-color: rgba(102, 126, 234, 0.5);
        box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1),
          0 8px 25px rgba(102, 126, 234, 0.15);
        transform: translateY(-2px);
      }
    }
  }

  .input-icon {
    height: 52px;
    width: 24px;
    margin-left: 16px;
    color: rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.3s ease;
  }

  .el-form-item {
    margin-bottom: 20px;

    &:focus-within .input-icon {
      color: rgba(102, 126, 234, 0.8);
      transform: scale(1.1);
    }
  }

  .el-checkbox {
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 25px;
    font-weight: 400;

    .el-checkbox__input.is-checked .el-checkbox__inner {
      background-color: #667eea;
      border-color: #667eea;
    }

    .el-checkbox__inner {
      border-color: rgba(255, 255, 255, 0.3);
      background: rgba(255, 255, 255, 0.05);
    }
  }

  .el-button {
    height: 52px;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 1px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: #fff;
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);

    &::before {
      content: '';
      position: absolute;
      top: 0;
      left: -100%;
      width: 100%;
      height: 100%;
      background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
      transition: left 0.5s;
    }

    &:hover {
      transform: translateY(-3px);
      box-shadow: 0 15px 35px rgba(102, 126, 234, 0.4);

      &::before {
        left: 100%;
      }
    }

    &:active {
      transform: translateY(-1px);
      box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
    }
  }

  .link-type {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-weight: 500;
    margin-top: 15px;
    display: inline-block;
    transition: all 0.3s ease;
    position: relative;

    &::after {
      content: '';
      position: absolute;
      bottom: -2px;
      left: 0;
      width: 0;
      height: 1px;
      background: linear-gradient(90deg, #667eea, #764ba2);
      transition: width 0.3s ease;
    }

    &:hover {
      color: #fff;

      &::after {
        width: 100%;
      }
    }
  }
}

@keyframes formSlideIn {
  0% {
    opacity: 0;
    transform: translateY(40px) scale(0.95);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes borderRotate {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

// 其他组件样式
.login-tip {
  font-size: 13px;
  text-align: center;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 15px;
}

.login-code {
  width: 33%;
  height: 52px;
  float: right;

  img {
    height: 100%;
    cursor: pointer;
    vertical-align: middle;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);

    &:hover {
      transform: scale(1.05);
      border-color: rgba(102, 126, 234, 0.3);
      box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    }
  }
}

// 底部版权信息
.el-login-footer {
  height: 50px;
  line-height: 50px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
  font-family: 'Inter', 'Segoe UI', sans-serif;
  font-size: 13px;
  letter-spacing: 1px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  z-index: 10;
  background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.1) 100%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.login-code-img {
  height: 52px;
}

// 角色选择区域 - 现代化设计
.role-selection {
  margin-bottom: 30px;
  animation: roleSlideIn 0.8s ease-out 0.2s forwards;
  // 确保默认可见，动画失败时也能显示
  opacity: 1 !important;
  transform: translateY(0) !important;
  visibility: visible !important;
  display: block !important;

  // 如果支持动画，则使用动画效果
  @supports (animation: roleSlideIn) {
    opacity: 0;
    transform: translateY(30px);
  }

  // 强制显示规则，覆盖所有可能的隐藏样式
  &[style*="display: none"] {
    display: block !important;
  }

  &[style*="visibility: hidden"] {
    visibility: visible !important;
  }

  &[style*="opacity: 0"] {
    opacity: 1 !important;
  }

  .role-title {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.9);
    text-align: center;
    margin-bottom: 20px;
    font-weight: 500;
    letter-spacing: 2px;
    text-transform: uppercase;
    position: relative;

    &::after {
      content: '';
      position: absolute;
      bottom: -6px;
      left: 50%;
      transform: translateX(-50%);
      width: 40px;
      height: 2px;
      background: linear-gradient(90deg, #667eea, #764ba2);
      border-radius: 2px;
    }
  }

  .role-container {
    display: flex;
    justify-content: flex-start;
    gap: 16px;
    // 启用横向滚动，解决换行问题
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    padding: 8px 4px 12px 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;

    // 自定义滚动条样式
    &::-webkit-scrollbar {
      height: 6px;
    }

    &::-webkit-scrollbar-track {
      background: rgba(255, 255, 255, 0.1);
      border-radius: 3px;
    }

    &::-webkit-scrollbar-thumb {
      background: linear-gradient(90deg, #667eea, #8b5cf6);
      border-radius: 3px;
      transition: background 0.3s ease;
    }

    &::-webkit-scrollbar-thumb:hover {
      background: linear-gradient(90deg, #8b5cf6, #a855f7);
    }

    // 渐变遮罩效果，提示可滚动
    &::before,
    &::after {
      content: '';
      position: absolute;
      top: 0;
      width: 20px;
      height: 100%;
      pointer-events: none;
      z-index: 5;
      opacity: 0;
      transition: opacity 0.3s ease;
    }

    &::before {
      left: 0;
      background: linear-gradient(to right, rgba(102, 126, 234, 0.1), transparent);
    }

    &::after {
      right: 0;
      background: linear-gradient(to left, rgba(102, 126, 234, 0.1), transparent);
    }

    // 当内容可滚动时显示渐变遮罩
    &:hover {

      &::before,
      &::after {
        opacity: 1;
      }
    }

    .role-card {
      width: 100px;
      height: 85px;
      border-radius: 16px;
      background: rgba(255, 255, 255, 0.05);
      backdrop-filter: blur(15px);
      -webkit-backdrop-filter: blur(15px);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
      position: relative;
      overflow: hidden;
      border: 1px solid rgba(255, 255, 255, 0.1);
      // 确保卡片不会被压缩
      flex: 0 0 auto;
      min-width: 100px;

      // 在滚动容器中的特殊效果
      &:first-child {
        margin-left: 4px;
      }

      &:last-child {
        margin-right: 4px;
      }

      // 内发光效果
      &::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: linear-gradient(135deg,
            rgba(102, 126, 234, 0.1),
            rgba(118, 75, 162, 0.1));
        opacity: 0;
        transition: opacity 0.4s ease;
        z-index: 0;
      }

      // 光晕效果
      &::after {
        content: '';
        position: absolute;
        top: -50%;
        left: -50%;
        width: 200%;
        height: 200%;
        background: linear-gradient(45deg,
            transparent,
            rgba(255, 255, 255, 0.1),
            transparent);
        transform: rotate(45deg) translate(-100%, -100%);
        transition: transform 0.6s ease;
        z-index: 1;
      }

      &:hover {
        transform: translateY(-5px) scale(1.05);
        box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2),
          0 0 20px rgba(102, 126, 234, 0.3);
        border-color: rgba(102, 126, 234, 0.3);

        &::before {
          opacity: 1;
        }

        &::after {
          transform: rotate(45deg) translate(100%, 100%);
        }

        .role-icon {
          transform: translateY(-3px) scale(1.1);
          color: rgba(255, 255, 255, 0.9);
        }

        .role-label {
          color: rgba(255, 255, 255, 0.9);
        }
      }

      &.active {
        background: linear-gradient(135deg, #667eea, #764ba2);
        border-color: transparent;
        box-shadow: 0 20px 50px rgba(102, 126, 234, 0.4),
          0 0 30px rgba(102, 126, 234, 0.3);
        transform: translateY(-5px) scale(1.05);
        z-index: 2;

        &::before {
          opacity: 0;
        }

        .role-icon,
        .role-label {
          color: #fff;
          z-index: 3;
        }

        .role-icon {
          transform: translateY(-3px) scale(1.1);
        }

        .check-mark {
          opacity: 1;
          transform: scale(1) rotate(0deg);
        }
      }

      .role-icon {
        font-size: 24px;
        color: rgba(255, 255, 255, 0.7);
        margin-bottom: 8px;
        transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
        position: relative;
        z-index: 2;
      }

      .role-label {
        font-size: 12px;
        font-weight: 500;
        color: rgba(255, 255, 255, 0.7);
        transition: all 0.4s ease;
        position: relative;
        z-index: 2;
        text-align: center;
        padding: 0 8px;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        line-height: 1.2;
      }

      .check-mark {
        position: absolute;
        top: 8px;
        right: 8px;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: linear-gradient(45deg, #fff, #f0f8ff);
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0;
        transform: scale(0) rotate(-180deg);
        transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        z-index: 3;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);

        i {
          font-size: 12px;
          color: #667eea;
          font-weight: bold;
        }
      }
    }
  }
}

@keyframes roleSlideIn {
  0% {
    opacity: 0;
    transform: translateY(30px);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

// 响应式设计
@media (max-width: 768px) {
  .login-form {
    width: 90%;
    max-width: 400px;
    padding: 30px 25px;
    margin: 20px;
  }

  .title {
    font-size: 24px;
    margin-bottom: 25px;
  }

  .role-container {
    // 手机屏幕上优化滚动体验
    gap: 12px;
    padding: 6px 2px 10px 2px;

    .role-card {
      width: 90px;
      height: 80px;
      min-width: 90px;

      .role-icon {
        font-size: 20px;
      }

      .role-label {
        font-size: 11px;
      }
    }
  }
}

@media (max-width: 480px) {
  .login {
    padding: 20px;
  }

  .login-form {
    width: 95%;
    padding: 25px 20px;
  }

  .title {
    font-size: 22px;
  }

  .role-container {
    gap: 10px;
    padding: 4px 1px 8px 1px;

    .role-card {
      width: 80px;
      height: 75px;
      min-width: 80px;

      .role-icon {
        font-size: 18px;
        margin-bottom: 6px;
      }

      .role-label {
        font-size: 10px;
        line-height: 1.1;
      }

      .check-mark {
        width: 16px;
        height: 16px;
        top: 6px;
        right: 6px;

        i {
          font-size: 10px;
        }
      }
    }
  }

  .el-login-footer {
    font-size: 11px;
    padding: 0 10px;
  }
}

// 超宽屏幕优化（当角色较少时恢复居中布局）
@media (min-width: 1200px) {
  .role-container {

    // 当屏幕足够宽且角色不多时，使用居中布局
    &:has(.role-card:nth-child(-n+4):last-child) {
      justify-content: center;
    }
  }
}

// 高分辨率屏幕优化
@media (min-width: 1440px) {
  .login-form {
    width: 540px;
    padding: 40px 20px;
  }

  .title {
    font-size: 32px;
  }
}

// 深色模式兼容
@media (prefers-color-scheme: dark) {
  .login {
    background: linear-gradient(-45deg, #1a1a2e 0%, #16213e 50%, #2d1b69 100%);
  }
}

// 动画性能优化
@media (prefers-reduced-motion: reduce) {

  .login,
  .login::before,
  .login::after,
  .title,
  .login-form,
  .role-selection,
  .role-card {
    animation: none !important;
    transition: none !important;
  }
}
</style>
